#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
# Copyright (C) 2015-2016 GuoGuo <gch981213@gmail.com>
. /lib/functions.sh
START=95
USE_PROCD=1

start_service() {
	[ -f /etc/config/dns2socks ] || {
		echo "You are missing configuration file /etc/config/dns2socks"
		return 1
	}

	config_load "dns2socks"

	config_get ENABLED config enabled

	[ "$ENABLED" = "0" ] && {
		echo "dns2socks is disabled."
		return 1
	}

	config_get SOCKSSERVER config socksserver
	config_get SOCKSPORT config socksport
	config_get DNSSERVER config dnsserver
	config_get LOCALIP config localip
	config_get LOCALPORT config localport

	procd_open_instance
	procd_set_param command /usr/bin/dns2socks $SOCKSSERVER:$SOCKSPORT $DNSSERVER $LOCALIP:$LOCALPORT
	procd_set_param respawn
	procd_close_instance
}

reload_service() {
	restart
}
